package com.xxh.book.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MbUtil {

    public static SqlSessionFactory getSqlSessionFactory(){
        try {
            InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
            return new SqlSessionFactoryBuilder().build(stream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static SqlSession getSqlSession(){
        //mybatics自动提交是关闭的，设置为TRUE，才会使自动提交生效
       return getSqlSessionFactory().openSession(true);
    }
}
